package com.my.system.controller;


import com.my.core.controller.BaseController;
import com.my.response.Result;
import com.my.system.entity.SysDictData;
import com.my.system.service.ISysDictDataService;
import com.my.system.service.ISysDictTypeService;
import com.my.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author my
 * @since 2021-04-25
 */
@RestController
@RequestMapping("/dict/data")
@Api(value = "系统管理模块", tags = "数据字典接口")
public class SysDictDataController extends BaseController {

    private ISysDictDataService dictDataService;
    private ISysDictTypeService dictTypeService;

    public SysDictDataController(ISysDictDataService dictDataService, ISysDictTypeService dictTypeService) {
        this.dictDataService = dictDataService;
        this.dictTypeService = dictTypeService;
    }

    @GetMapping(value = "/type/{dictType}")
    @ApiOperation("根据字典类型查询字典数据信息")
    public Result dictType(@PathVariable String dictType) {
        List<SysDictData> dicts = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(dicts)) {
            dicts = new ArrayList<SysDictData>();
        }
        return Result.ok("").data("dicts", dicts);
    }

}

